package com.geektime.hello;

import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FindMP4UrlDemo {
    public static void main(String[] args) {
        String html1 = "<video src=\"https://vodpub1.v.news.cn/original/20200923/474f501532364c53bf3231ad77859520.mp4\" webkit-playsinline=\"true\" x5-playsinline=\"true\" autoplay=\"\" preload=\"auto\" playsinline=\"true\" poster=\"https://vodpub1.v.news.cn/original/image/cd3e24f6472c45afb5836c2f56729dc4_videogroup_1067_600_0.jpg\" tabindex=\"0\" class=\"dhy-video\" id=\"dhy-video\"></video>";
        String html2 = "<source src=\"http://video.anhuiyun.com/qukanvideo/userUpload/1573721679593913/1587092533622900/vod/c316da0c-68a1-4e24-9e59-d11d16a45efd.mp4\" type=\"video/mp4\">\n" +
                "                                <source src=\"http://video.anhuiyun.com/qukanvideo/userUpload/1573721679593913/1587092533622900/vod/c316da0c-68a1-4e24-9e59-d11d16a45efd.mp4\" type=\"video/webm\">\n" +
                "                                <source src=\"http://video.anhuiyun.com/qukanvideo/userUpload/1573721679593913/1587092533622900/vod/c316da0c-68a1-4e24-9e59-d11d16a45efd.mp4\" type=\"video/ogg\">\n" +
                "                                <!-- <p class=\"vjs-no-js\">\n" +
                "                                To view this video please enable JavaScript, and consider upgrading to a web browser that\n" +
                "                                <a href=\"http://videojs.com/html5-video-support/\" target=\"_blank\">supports HTML5 video</a>\n" +
                "                                </p> -->";

        String pattern = "[a-zA-z]+://[^\\s]*\\.mp4";

        Set<String> set = new HashSet<>();

        Pattern r = Pattern.compile(pattern);
        Matcher m = r.matcher(html2);
        while (m.find()) {
            set.add(m.group());
        }
        System.out.println(set);
    }
}
